#include <allegro.h>
#include "carte_final.h"



int main ()
{
BITMAP* plaque_v;
BITMAP* gris;
BITMAP* gun;
BITMAP* knife;
BITMAP* watch;
BITMAP* plaque_vides;
BITMAP* buffer;
BITMAP* curseur;
BITMAP* result;

int s_check_1=0,s_check_2=0, pos=0, c_s=0;
int mb_check_1=0, mb_check_2=0, pos1=0, c_mb=0;
int p_check_1=0, p_check_2=0, pos2=0, c_p=0;
int score=0 ;

int nbrC= 0;

/* General initialization function */

allegro_init();

 install_keyboard() ;

if (install_keyboard() == -1) 
 {
  allegro_message("Error! %s", allegro_error);
  return (-1);
 }

 install_mouse() ;

if (install_mouse () == -1)
  {
  allegro_message("Erreur ! %s", allegro_error) ;
  return -1 ;
  }

set_color_depth(32);

if (set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0) != 0) 
  {
   set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
   allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
   return (1);
  }

load (&plaque_v , &gris ,&gun ,&knife ,&watch ,&plaque_vides, &curseur,&result,&buffer );



   while(!key[KEY_ESC] )

{

clear_bitmap(buffer) ;

draw_sprite(buffer, plaque_vides, p1, y_up1);
draw_sprite(buffer, curseur, mouse_x, mouse_y);

//GUN 1

if (mouse_x < p11 && mouse_x > p1 && mouse_y < y_up2 && mouse_y > y_up1 && (mouse_b & 1))
{
   draw_sprite(buffer, gun, p1, y_up1);	
   s_check_1=1;c_s+=10;
	
//usleep(100000);

if(nbrC== 2 || nbrC == 0)
{
  
  nbrC=1;

}

else
{

nbrC=2;

}

}

//WATCH 1

else if (mouse_x < p22 && mouse_x > p2 && mouse_y < y_up2 && mouse_y > y_up1 && (mouse_b & 1))
{

   draw_sprite(buffer, watch, p2, y_up1);	
   draw_sprite(buffer, curseur, mouse_x, mouse_y);
   p_check_1=1;c_p+=10;
	
//usleep(100000);

if(nbrC== 2 || nbrC == 0)
{

nbrC=1;

}

else
{

nbrC=2;

}

}
//KNIFE 1

 else if (mouse_x < p33 && mouse_x > p3 && mouse_y < y_up2 && mouse_y > y_up1 && (mouse_b & 1))
{
	draw_sprite(buffer, knife, p3, y_up1);	
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
	mb_check_1=1;c_mb+=10;

//usleep(100000);

  if(nbrC== 2 || nbrC == 0)
  {
   nbrC=1;
  }  

  else
  {
  nbrC=2;
  }

	
}
//KNIFE 1

else if (mouse_x < p11 && mouse_x > p1 && mouse_y < y_down2 && mouse_y > y_down1 && (mouse_b & 1))
{

	draw_sprite(buffer, knife, p1, y_down1);	
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
	mb_check_2=1;c_mb+=10;
//usleep(100000);
	
if(nbrC== 2 || nbrC == 0)
{

nbrC=1;

}

else
{

nbrC=2;

}

}

//WATCH 1
 else if (mouse_x < p22 && mouse_x > p2 && mouse_y < y_down2 && mouse_y > y_down1 && (mouse_b & 1))
{
    draw_sprite(buffer, watch, p2, y_down1);	
    draw_sprite(buffer, curseur, mouse_x, mouse_y);
    p_check_2=1;
    c_p+=10;
//usleep(100000);	

if(nbrC== 2 || nbrC == 0)
{

nbrC=1;

}

else
{

nbrC=2;

}

	
}
//GUN
 else if (mouse_x < p33 && mouse_x > p3 && mouse_y < y_down2 && mouse_y > y_down1 && (mouse_b & 1))
{

	draw_sprite(buffer, gun, p3, y_down1);	
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
	s_check_2=1;c_s+=10;
//usleep(100000);	

if(nbrC== 2 || nbrC == 0)
{

nbrC=1;

}
else
{

nbrC=2;

}

	
}

//GUN check
if(nbrC==2)
{
if (((s_check_1)==1) && ((s_check_2)==1))
{
	
        pos=1;
}

// WATCH check
if (((p_check_1)==1) && ((p_check_2)==1))
{
	
	(pos2)=1;
}

//KNIFE check
if (((mb_check_1)==1) && ((mb_check_2)==1))
{
	
	pos1=1;
}
s_check_1=0; s_check_2=0;
p_check_1=0; p_check_2=0;
mb_check_1=0; mb_check_2=0;
}

if ((pos) == 1)
{
  draw_sprite(buffer, gun, p1, y_up1);	
  draw_sprite(buffer, gun, p3, y_down1);
  draw_sprite(buffer, curseur, mouse_x, mouse_y);
}

if ((pos1) == 1)
{
        draw_sprite(buffer, knife, p3, y_up1);	
	draw_sprite(buffer, knife, p1, y_down1);
	draw_sprite(buffer, curseur, mouse_x, mouse_y);	
}

if ( (pos2) == 1)
{
draw_sprite(buffer, watch, p2, y_up1);	
	draw_sprite(buffer, watch, p2, y_down1);
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
}

//FINAL check
if ( (pos) == 1 && (pos2) == 1 && (pos1) == 1)
{ 	
	
   (score) =  (c_s) + (c_mb) + (c_p);  	
   textprintf(buffer, font, 100, 400, makecol(255,255,255 ), "FELICITATIONS VOTRE SCORE EST ** %i **",score);
   draw_sprite(buffer, result,SCREEN_W-result->w,SCREEN_H-result->h);	
   draw_sprite(buffer, curseur, mouse_x, mouse_y); 
            
}

vsync(); //plus rapide

blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H) ;

}

destroy(&gris ,&gun ,&knife ,&watch ,&plaque_vides,&curseur,&result,&buffer );


return 0;
}
END_OF_MAIN();

